<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
	<!--通用的header-->
	<jsp:include page="/views/includes/base_header.jsp">
		<jsp:param value="学生管理" name="title"/>
	</jsp:include>
	
	<body>
		<!--导航条-->
		<jsp:include page="/views/includes/top_navbar.jsp"></jsp:include>
		
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-2">
					<!--菜单栏-->		
					<jsp:include page="/views/includes/left_menu.jsp">
						<jsp:param value="dept_manage" name="active"/>
					</jsp:include>
				</div>
				<div class="col-md-1"></div>
				<div class="col-md-6">
					<div class="panel panel-primary">
						<div class="panel-heading">
						<c:if test="${testStu==null}">
							添加学生
						</c:if>
						<c:if test="${testStu!=null}">
							修改学生
						</c:if>	
						</div>
						<div class="panel-body"">
							
							<form  class="form-horizontal"  role="form" onsubmit="return false;">
								<!-- 作用域有学生信息，才设置id，当前为修改操作 -->
								<c:if test="${testStu!=null}">
									<div class="form-group">
										<label for="id" class="col-sm-2 control-label">编号</label>
										<div class="col-sm-10">
											<input  id="id" name="id" readonly="readonly" 
											 type="text" class="form-control" 
											 value="${testStu.id}"
											 >
										</div>
									</div>
								</c:if>
								
									<div class="form-group">
										<label for="sname" class="col-sm-2 control-label">学生名字</label>
										<div class="col-sm-10">
											<input id="sname" name="sname"  type="text" 
												   class="form-control" 
												   placeholder="请输入学生名字"
												   value='${testStu.sname}'
												   >
										</div>
									</div>
									<div class="form-group">
										<label for="sage" class="col-sm-2 control-label">学生年龄</label>
										<div class="col-sm-10">
											<input id="sage" name="sage"  type="text" 
												   class="form-control" 
												   placeholder="请输入学生年龄"
												   value='${testStu.sage}'
												   >
										</div>
									</div>
									<div class="form-group">
										<label for="studyDate" class="col-sm-2 control-label">入学时间</label>
										<div class="col-sm-10">
											<input id="studyDate" name="studyDate"  type="text" 
												   class="form-control" 
												   placeholder="请输入入学时间"
												   value='${testStu.studyDate}'
												   >
										</div>
									</div>
								
							
								<div class="form-group">
									<div class="col-sm-offset-2 col-sm-10">
										<button onclick="saveOrUpdateData()" class="btn btn-success">保存</button>
										<button type="reset"  class="btn btn-info">重置</button>
									</div>
								</div>
								
								
							 </form>
							
						</div>
						
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
	
	/**
		设置时期格式form表单
	*/
	
			Zxx.setDateTimeInput(false,true,'studyDate');
	
	/**
		添加或修改数据
	*/
	function saveOrUpdateData(){
		//是否保存的操作==没有id=id的input则会保存
		var isSaveOp=$("#id").size()==0;
		
		//设置添加或修改的url
		var opUrl=isSaveOp ?'/testStu/save':'/testStu/update';
		var opName=isSaveOp? '保存':'修改';
		//alert(opUrl);
		$.ajax({
			   type: "POST",
			   url: '${pageContext.request.contextPath}'+opUrl,
			   data: $("form").serialize(),
			   dataType:'json',
			   success: function(jsonObj){
				    if (jsonObj.status == 200) {
				    	//等待时间
				    	var time=1;
				    	Zxx.notice(opName+"成功！"+time+"秒无操作将回到查询界面");
						//清空信息
						if(isSaveOp){
							$("button[type='reset']").click()
						}
						//跳转到查询页面
						var goFindTimeOut= setTimeout(function() {
							window.location.href="${pageContext.request.contextPath}/testStu/findListCusTypeByCondition";	
						}, time*1000);
						//如果再输入内容=自动停止跳转
						$('input').click(function(){
							clearTimeout(goFindTimeOut);
						});
					} else {
						Zxx.notice(opName+"失败！原因是：" + jsonObj.msg);
					} 
			   }
			});
	}
</script>

</html>